package com.cn.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.cn.entity.Department;
import com.cn.entity.Taocan;
import com.cn.entity.TiJianxiangmu;


public class TaocanDao {
	

	private static SessionFactory sessionFactory;
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	Session session;

	
	
	public List<Taocan> scanAll(){
		session=sessionFactory.openSession();
		String hql="from Taocan";
		Query query=session.createQuery(hql);
		List<Taocan> list=query.list();
	   
	     return list;
		
		
	}
	public Taocan scanOne(int taocanid){
		Taocan taocan=null;
		session=sessionFactory.openSession();
		String hql="from Taocan where taocanid=?";
		Query query=session.createQuery(hql);
		query.setInteger(0, taocanid);
		List<Taocan> list=query.list();
	   
		if (list.size()>0){taocan=list.get(0);}
		
	     return taocan;
		
		
	}

	public void add(Taocan taocan){
		session=sessionFactory.openSession();
		Transaction tr=session.beginTransaction();
		
		session.save(taocan);
		tr.commit();
		session.close();
		
		
		
	}
	
	public void update(Taocan taocan){
		session=sessionFactory.openSession();
		Transaction tr=session.beginTransaction();
		
		session.update(taocan);
		tr.commit();
		session.close();
		
		
		
	}
	
	public void delete(Taocan taocan){
		
		Transaction tr=session.beginTransaction();
		
		session.delete(taocan);
		tr.commit();
		session.close();
		
		
		
	}
	
	public Taocan scanOne(String taocanming){
		Taocan taocan=null;
		session=sessionFactory.openSession();
		String hql="from Taocan where taocanming=?";
		Query query=session.createQuery(hql);
		query.setString(0, taocanming);
		List<Taocan> list=query.list();
	   
		if (list.size()>0){taocan=list.get(0);}
		
	     return taocan;
		
		
	}
	
}
